//
// CppFunCallbackStream.hpp for CppFunCallbackStream in /home/mambou_j//babel-2014
// 
// Made by jacquesquentin mamboumouafo
// Login   <mambou_j@epitech.net>
// 
// Started on  Fri May 11 01:35:28 2012 jacquesquentin mamboumouafo
// Last update Fri May 11 02:07:18 2012 jacquesquentin mamboumouafo
//


#ifndef	__CPPFUNCALLBACKSTREAM_HPP__
#define	__CPPFUNCALLBACKSTREAM_HPP__

#include	"portaudio.h"
#include	"CallbackStream.hpp"

// Forward declaration(s):
namespace	portaudio
{
  class	StreamParameters;
}

// Declaration(s):
namespace	portaudio
{

	namespace	impl
	{
		extern "C"
		{
		  int	cppCallbackToPaCallbackAdapter(const void *inputBuffer, void *outputBuffer, unsigned long numFrames, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
		}
	}

  /////
  /// @brief Callback stream using a C++ function (either a free function or a
  /// static function)
  /// callback.
  /////
  class	FunCallbackStream	:	public	CallbackStream
  {
  public:
    typedef	int	(*CallbackFunPtr)(const void *inputBuffer, void *outputBuffer, unsigned long numFrames, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData);

    /////
    /// @brief Simple structure containing a function pointer to the C++
    /// callback function and a (void) pointer to the user supplied data.
    //////
    struct	CppToCCallbackData
    {
      CppToCCallbackData();
      CppToCCallbackData(CallbackFunPtr funPtr, void *userData);
      void	init(callbackFunPtr funPtr, void *userData);

      CallbackFunPtr funPtr;
      void	*userData;
    };

    FunCallbackStream();
    FunCallbackStream(const StreamParameters &parameters, CallbackFunPtr funPtr, void *userData);
    ~FunCallbackStream();

    void	open(const StreamParameters &parameters, CallbackFunPtr funPtr, void *userData);

  private:
    FunCallbackStream(const FunCallbackStream &);
    FunCallbackStream &operator=(const FunCallbackStream &);

    CppToCallbackData	adapterData_;

    void	open(const StreamParameters &parameters);
  };
}

#endif
